import requests
import time
import hashlib
import json

#获取token
def token():
    m = hashlib.md5()#md5加密
    headers = {'content-type': 'application/json'}#请求头
    ctime = int(time.time())  # 当前时间戳
    tosign = 'accessKey' + '4ac0fd1452c64521a94a0faaf830d906' + 'timestamp' + str(ctime)
    # print('tosign=' + tosign)
    tosign1 = (tosign + 'uUS49o6T/gGBtFtVxgfW9/nGdvyyO+Ri/0kPyN93hm6N8PzTgZIa/ReKthjVYPBF').upper()
    # print('tosign1=' + tosign1)
    b = tosign1.encode(encoding='utf-8')
    m.update(b)
    sign = m.hexdigest()
    # print('sign=' + sign)
    payload = {'accessKey': '4ac0fd1452c64521a94a0faaf830d906', 'timestamp': ctime, 'sign': sign}#请求体
    ret = requests.post("http://shop.5913ex.com/api/v1/authorization/getToken", data=json.dumps(payload), headers=headers)
    # print(ret.text)
    return ret.json()['data']

















